﻿Imports Cls_Common
Imports VSModel
Partial Class Control_MSDS_PrintLabelHTML
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindData()
        End If
    End Sub
    Protected Sub BindData()
        Using _data As New VSEntities
            Dim _batch As String = Request("Id")
            Dim p = _data.uspLabelPrintByBatchNo(_batch).FirstOrDefault
            If Not p Is Nothing Then
                ltrMaCode.Text = ""
                If Not p.CASNo Is Nothing AndAlso p.CASNo <> "" Then
                    ltrMaCode.Text = ltrMaCode.Text & "CAS: " & p.CASNo
                End If
                If Not p.ECNo Is Nothing AndAlso p.ECNo <> "" Then
                    ltrMaCode.Text = ltrMaCode.Text & " EC: " & p.ECNo
                End If
                If Not p.UNNo Is Nothing AndAlso p.UNNo <> "" Then
                    ltrMaCode.Text = ltrMaCode.Text & " UN: " & p.UNNo
                End If
                If Not p.MaSanPham Is Nothing AndAlso p.MaSanPham <> "" Then
                    ltrMaCode.Text = ltrMaCode.Text & " Mã sản phẩm: " & p.MaSanPham
                End If
                If Not p.TradeName Is Nothing AndAlso p.TradeName <> "" Then
                    ltrTenHoaChat.Text = p.TradeName
                End If
                ltrMaSo.Text = "Mã số: " & p.ItemCode & " Mã vendor: " & p.VendorCode

                ltrManuName.Text = IIf(IsNothing(p.ManufactureName) = True, "", p.ManufactureName)
                ltrManuAdd.Text = IIf(IsNothing(p.ManuAddress) = True, "", p.ManuAddress)
                ltrManuTel.Text = IIf(IsNothing(p.ManuDienThoai) = True, "", p.ManuDienThoai)
                ltrManuFax.Text = IIf(IsNothing(p.ManuFax) = True, "", p.ManuFax)


                ltrProName.Text = IIf(IsNothing(p.ProName) = True, "", p.ProName)
                ltrProAdd.Text = IIf(IsNothing(p.ProAddress) = True, "", p.ProAddress)
                ltrProTel.Text = IIf(IsNothing(p.ProDienThoai) = True, "", p.ProDienThoai)
                ltrProFax.Text = IIf(IsNothing(p.ProFax) = True, "", p.ProFax)

                ltrOriginal.Text = IIf(IsNothing(p.Original) = True, "", p.Original)
                ltrDinhLuong.Text = IIf(IsNothing(p.Netweight) = True, "", p.Netweight) & " " & IIf(IsNothing(p.DonVi) = True, "", p.DonVi) & " / " & IIf(IsNothing(p.DVT) = True, "", p.DVT)
                If Not p.NgaySanXuat Is Nothing Then
                    ltrNgaySanXuat.Text = CType(p.NgaySanXuat, Date).ToString("dd/MM/yyyy")
                End If
                If Not p.HanSuDung Is Nothing Then
                    ltrNgayHetHan.Text = CType(p.HanSuDung, Date).ToString("dd/MM/yyyy")
                End If

                If Not p.ThanhPhan_1 Is Nothing AndAlso p.ThanhPhan_1.Trim() <> "CAS:" Then
                    ltrThanhPhan.Text = "<div>" & p.ThanhPhan_1 & "</div>"
                End If
                If Not p.ThanhPhan_2 Is Nothing AndAlso p.ThanhPhan_2.Trim() <> "CAS:" Then
                    ltrThanhPhan.Text = ltrThanhPhan.Text & "<div>" & p.ThanhPhan_2 & "</div>"
                End If
                If Not p.ThanhPhan_3 Is Nothing AndAlso p.ThanhPhan_3.Trim() <> "CAS:" Then
                    ltrThanhPhan.Text = ltrThanhPhan.Text & "<div>" & p.ThanhPhan_3 & "</div>"
                End If
                If Not p.ThanhPhan_4 Is Nothing AndAlso p.ThanhPhan_4.Trim() <> "CAS:" Then
                    ltrThanhPhan.Text = ltrThanhPhan.Text & "<div>" & p.ThanhPhan_4 & "</div>"
                End If
                If Not p.ThanhPhan_5 Is Nothing AndAlso p.ThanhPhan_5.Trim() <> "CAS:" Then
                    ltrThanhPhan.Text = ltrThanhPhan.Text & "<div>" & p.ThanhPhan_5 & "</div>"
                End If
                'canh bao 
                Dim k = _data.uspLabelGetHinhDo(_batch, 1).ToList.Take(4)
                Dim strTuCanhBao = ""
                Dim strCanhBaoNguyCo = ""
                Dim i As Integer = 1
                For Each a In k
                    strTuCanhBao = strTuCanhBao & "," & a.TuCanhBao
                    strCanhBaoNguyCo = strCanhBaoNguyCo & "," & a.CanhBaoNguyCo
                    If i = 1 Then
                        ltrPicOne.Text = "<img src='" & a.FileURL & "' width='120px'/>"
                    End If
                    If i = 2 Then
                        ltrPicThree.Text = "<img src='" & a.FileURL & "' width='120px'/>"
                    End If
                    If i = 3 Then
                        ltrPicFour.Text = "<img src='" & a.FileURL & "' width='120px'/>"
                    End If
                    If i = 4 Then
                        ltrPicThree.Text = "<img src='" & a.FileURL & "' width='120px'/>"
                    End If
                    i = i + 1
                Next

                ltrTuCanhBao.Text = IIf(strTuCanhBao.Contains("Nguy hiểm"), "Nguy hiểm", IIf(strTuCanhBao.Contains("Cảnh báo") And strTuCanhBao.Length < 10, "Cảnh báo", "Không có từ cảnh báo"))
                ltrCanhBaoNguyCo.Text = strCanhBaoNguyCo
            End If
        End Using
    End Sub


End Class
